using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace shfa.snomtastic.data
{
    public partial class SqlDataProvider
    {

        public Guid InsertSubcategory(Guid categoryId, string name)
		{
            return new Guid(Convert.ToString(SqlHelper.ExecuteScalar(ConnectionString, "sp_SubcategoryInsert", GetNull(categoryId), name)));
		}

        public int UpdateSubcategory(Guid subcategoryId, Guid categoryId, string name)
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_SubcategoryUpdate", GetNull(subcategoryId), GetNull(categoryId), name));
		}

        public int DeleteSubcategory(Guid subcategoryId) 
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_SubcategoryDelete", subcategoryId));
		}

        public DataRow SelectSubcategory(Guid subcategoryId) 
        {    
			DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_SubcategorySelect", subcategoryId);
            if (ds.Tables.Count > 0)
                if (ds.Tables[0].Rows.Count > 0)
                    return ds.Tables[0].Rows[0];

            return null;
		}

		public DataTable SelectSubcategories() 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_SubcategorySelectAll").Tables[0];
        }

		public DataTable SelectSubcategoriesByCategory(Guid categoryId) 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_SubcategorySelectByCategory", categoryId).Tables[0];
        }

    }

}
